<?php
defined('IN_IA') or exit('Access Denied');
global $_W, $_GPC;
$docurl = $_GPC['docurl'];
set_time_limit(60);
include_once '../addons/bsht_tbk/plus/excel/oleread.php';
include_once '../addons/bsht_tbk/plus/excel/excel.php';
if ($docurl) {
	$xls = new Spreadsheet_Excel_Reader();
	$xls->setOutputEncoding('utf-8');
	$xls->read($docurl);
	for ($i = 2; $i <= $xls->sheets[0]['numRows']; $i++) {
		$data_values[] = $xls->sheets[0]['cells'][$i];
	}
	$inert_sql = "INSERT INTO " . tablename('bsht_tbk_caiji') . " (*) ";
	$insert_val = "";
	$count = 0;
	$cateid = 0;
	foreach ($data_values as $value) {
		if ($value[1] == '') {
			break;
		}
		if ($value[1] != '') {
			$cate = pdo_fetch('select * from ' . tablename('bsht_tbk_caiji') . " where itemid = '{$value[1]}' and uniacid = '{$_W['uniacid']}' limit 1");
			if (empty($cate)) {
				$cate_data = array('uniacid' => $_W['uniacid'], 'displayorder' => '0', 'itemid' => $value[1], 'title' => $value[2], 'itempic' => $value[3], 'shoptitle' => $value[5], 'itemfee' => $value[6], 'itemmsell' => $value[7], 'itemstatus' => '普通商品', 'itemsurl' => $value[11], 'itemurl' => $value[12], 'itemtkl' => $value[13], 'itemyhj_zl' => $value[14], 'itemyhj_yl' => $value[15], 'itemyhj_tit' => $value[16], 'itemyhj_stime' => $value[17], 'itemyhj_etime' => $value[18], 'itemyhj_url' => $value[19], 'itemyhj_tkl' => $value[20], 'status' => 1);
				pdo_insert('bsht_tbk_caiji', $cate_data);
				$cateid = pdo_insertid();
			} else {
				$cateid = $cate['id'];
			}
			continue;
		}
		if (!empty($insert_val)) {
			$insert_val .= ", ";
		}
		$insert_val .= " ( * ) ";
		$count++;
	}
	message('导入成功！', referer(), 'success');
} else {
	message('导入失败，请检查文件或运行环境！', referer(), 'error');
}